import Vue from 'vue'
import App from './App'
import axios from 'axios'
import VueAxios from 'vue-axios'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import store from './store'
import router from './router/index'
import Cookie from 'js-cookie'
import animated from 'animate.css'
import './editor-content-view.css'
Vue.config.productionTip = false
Vue.use(animated)
Vue.use(VueAxios, axios)
Vue.use(ElementUI)

// 全局路由守卫
router.beforeEach((to, from, next) => {
  const userInfo = Cookie.get('token')
  if (!userInfo && to.name !== 'login') {
    next({ name: 'login' })
  } else if (userInfo && to.name === 'login') {
    next({ name: 'home' })
  } else {
    next()
  }
})
// eslint-disable-next-line no-new
new Vue({
  el: '#app',
  store,
  router,
  components: { App },
  template: '<App/>'
})
